package com.zhentao.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.DepartmentMapper;
import com.zhentao.mapper.TbDoctorMapper;
import com.zhentao.pojo.TbDoctor;
import com.zhentao.service.TbDoctorService;
import com.zhentao.vo.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author lenovo
* @description 针对表【tb_doctor】的数据库操作Service实现
* @createDate 2025-07-31 17:24:22
*/
@Service
public class TbDoctorServiceImpl extends ServiceImpl<TbDoctorMapper, TbDoctor>
    implements TbDoctorService{
    @Autowired
    private TbDoctorMapper tbDoctorMapper;
    @Autowired
     DepartmentMapper departmentMapper;
    @Override
    public Page<TbDoctor> findPage(Query query) {
        // 1. 初始化分页（page=当前页，size=每页条数）
        Page<TbDoctor> page = new Page<>(query.getPage(), query.getSize());

        // 2. 构建查询条件
        QueryWrapper<TbDoctor> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(query.getDoctorName())) {
            wrapper.like("doctor_name", query.getDoctorName()); // 模糊查询医生姓名
        }
        if (StringUtils.isNotBlank(query.getDepartment())) {
            wrapper.like("department", query.getDepartment()); // 模糊查询科室
        }

        // 3. 执行分页查询
        return tbDoctorMapper.selectPage(page, wrapper);
    }
}




